package com.codergd.gra.controller;

import com.codergd.gra.bean.Com;
import com.codergd.gra.config.PageQuery;
import com.codergd.gra.config.PageResult;
import com.codergd.gra.config.RestResult;
import com.codergd.gra.config.ResultGenerator;
import com.codergd.gra.service.ComService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/com")
public class ComController {

    @Autowired
    ComService comService;

    @PostMapping("/isLogin")
    public int isLogin(String iphone,String password){
        return comService.isLogin(iphone,password);
    }

    @PostMapping("/selectCom1")
    public List<Com> selectCom1(String comname){
        return comService.selectCom1(comname);
    }

    @PostMapping("/registered")
    public int registered(Com com){
        return comService.registered(com);
    }

    //根据手机号查找id
    @PostMapping("/selectId")
    public int selectId(HttpServletRequest request){
        return comService.selectId(request.getParameter("iphone"));
    }

    //根绝id查企业
    @PostMapping("/selectComById")
    public List<Com> selectComById(int id){
        return comService.selectComById(id);
    }

    @PostMapping("/selectCom")
    public List<Com> selectCom2(){
        return comService.selectCom2();
    }

    //修改企业状态
    @PostMapping("/updateState")
    public int updateState(int id,int state){
        return comService.updateState(id,state);
    }

    //修改企业信息
    @PostMapping("/updateCom")
    public int updateCom(int id,String iphone,String comname,String password,String address,String manage,String introduce){
        System.out.println(id);
        return comService.updateCom(id,iphone,comname,password,address,manage,introduce);
    }

    //分页查询人才
    @GetMapping("/page")
    public RestResult page(PageQuery pageQuery){

        PageResult pageResult = comService.pageQuery(pageQuery);
        return RestResult.success(pageResult);
    }
}
